<template>
  <el-select style="width:100%" filterable v-model="model" v-bind="$attrs" clearable v-on="$listeners">
    <template v-for="(item) of options">
      <el-option :key="item.id" :label="item.checkTypeName" :value="item.id"></el-option>
    </template>
  </el-select>
</template>

<script>
import { listCommonCheckType } from '@/api/cases/commonCheckType'
export default {
  model: {
    prop: "value",
    event: "change"
  },
  data() {
    return {
      options: []
    }
  },
  props: {
    value: {
      type: [String, Number],
      default: undefined
    },
    parentId: {
      type: [String, Number],
      required: false
    },
  },
  computed: {
    model: {
      get() {
        return this.value ? Number(this.value) : void 0
      },
      set(value) {
        this.$emit("change", value)
      }
    }
  },
  watch: {
    parentId() {
      if(this.parentId == "" || this.parentId == null || this.parentId == void 0){
          this.options = [];
      }else{
        this.getTypes();
      }
    }
  },
  async mounted() {
      if(this.parentId == void 0){
          this.options = []
      }else{
        this.getTypes();
      }
  },
  methods: {
    /**
     * 清理
     */
    async clear(){
      this.$emit("change", "");
    },
    /**
     * 获取类型
     */
    getTypes() {
      return new Promise((resolve,reject)=>{
        let params = {
          parentId: this.parentId,
          status: 0,
          delFlag:0
        }
        listCommonCheckType(params).then(res => {
          this.options = res.data;
          resolve()
        }).catch(error => {
          this.options = []
          reject();
        })
      })
    }
  }
}
</script>

<style>
</style>